<?php
namespace FileManage\Controller;

use Think\Controller;
use Org\Net\Http;

class Test
{
	public $code;
	public $msg;
	public $count;
	public $data;
}

class FileController extends Controller
{
    //对应三个文件夹，三个部分
    public function ShowConfer()
    {
        $this->display();
    }

    public function ShowStudy()
    {
        $this->display();
    }

    public function ShowTrain()
    {
        $this->display();
    }

    //传值
    public function PassConfer($page,$limit)
    {
        $test = new Test();
        $data = D('Conference');
        $start = ($page - 1) * $limit;
        $result = $data
            ->join('sz_user ON sz_conference.author=sz_user.id')
            ->field('sz_conference.id,filename,filesave,date,name')//filename 文件名  date 上传时间  name 上传人  （id用于排序，filesave用于查找）
            ->order('sz_conference.id desc')
            ->limit($start, $limit)
            ->select();
        $count = $data->count();
        $test->code = 0;
        $test->msg = "";
        $test->count = $count;
        $test->data = $result;
        $this->ajaxReturn($test);
    }

    public function PassStudy()
    {
        $test = new Test();
        $data = D('Note');
        $start = ($page - 1) * $limit;
        $result = $data
            ->join('sz_user ON sz_note.edit=sz_user.id')
            ->field('sz_note.id,file,savefile,time,name')//file 文件名  time 上传时间  name 上传人   （id用于排序，savefile用于查找）
            ->order('sz_note.id desc')
            ->limit($start, $limit)
            ->select();
        $count = $data->count();
        $test->code = 0;
        $test->msg = "";
        $test->count = $count;
        $test->data = $result;
        $this->ajaxReturn($test);
    }

    public function PassTrain()
    {
        $test = new Test();
        $data = D('Train');
        $start = ($page - 1) * $limit;
        $result = $data
            ->join('sz_user ON sz_train.host=sz_user.id')
            ->field('sz_train.id,filename,savename,date,name')//filename 文件名  date 上传时间  name 上传人   （id用于排序，savename用于查找）
            ->order('sz_train.id desc')
            ->limit($start, $limit)
            ->select();
        $count = $data->count();
        $test->code = 0;
        $test->msg = "";
        $test->count = $count;
        $test->data = $result;
        $this->ajaxReturn($test);
    }

    //下载
    
    //会议记录下载
    public function DownloadConfer()
    {
        import('Org.Net.Http');
        $id = I('get.id');
        $where['id'] = $id;
        $Conference = D('Conference');
        $result = $Conference->field('filesave')->where($where)->find();
        $url = './Public/Meeting/'.$result['filesave'];
        Http::download($url, $result['filesave']);
    }

    //学习记录文件下载
    public function DownloadStudy()
    {
        import('Org.Net.Http');
        $id = I('get.id');
        $where['id'] = $id;
        $Note = D('Note');
        $result = $Note->field('savefile')->where($where)->find();
        $url = './Public/Note/' . $result['savefile'];
        Http::download($url, $result['savefile']);
    }

    //培训记录文件下载
    public function DownloadTrain()
    {
        import('Org.Net.Http');
        $id = I('get.id');
        $where['id'] = $id;
        $Train = D('Train');
        $result = $Train->field('savename')->where($where)->find();
        $url = './Public/Train/' . $result['savename'];
        Http::download($url, $result['savename']);
    }
}